package net.xdclass.base_project.task;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

/**
 * @author sqz
 * @Description: 定时任务业务类
 * @date 2019/3/23 13:35
 */
@Component
public class TestTask {
    //@Scheduled(fixedRate = 2000)
    //@Scheduled(cron = "*/2 * * * * *")
    //@Scheduled(fixedDelay = 2000)
//    @Scheduled(fixedDelayString = "2000")
//    @Scheduled(fixedRateString = "2000")
    //@Scheduled(initialDelay=2000, fixedRate=5000)
    public void sum() throws InterruptedException {
        Thread.sleep(4000);
        System.out.println("当前时间"+new Date());
    }
    @Scheduled(fixedRate = 10000)
    public void testReflush() throws InterruptedException, IOException {
        System.out.println("次数");
        String url = "https://blog.csdn.net/qq_33355821/article/details/85676517"; //需要刷的博文的url
        //String url = "https://blog.csdn.net/qq_33355821/article/details/88057926"; //需要刷的博文的url
        // 创建默认的客户端实例
        CloseableHttpClient httpclient = HttpClients.createDefault();
        // 创建get请求实例
        HttpGet httpget = new HttpGet(url);
        // 设置头部信息
        httpget.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2");
        // 客户端执行get请求 返回响应实体
        HttpResponse response = httpclient.execute(httpget);
        // 获取响应消息实体
        HttpEntity entity = response.getEntity();
    }
}
